package model

import (
	"api/database"
	"github.com/jinzhu/gorm"
)

type DeviceTopicModel struct {
	BaseModel
	gorm.Model
	Topic string
	Explain string
	Did uint
}

func NewDeviceTopicModel() *DeviceTopicModel {
	return &DeviceTopicModel{}
}

func (DeviceTopicModel) TableName() string {
	return "device_topic"
}

func (dt DeviceTopicModel) Insert() (interface{},error) {
	database.GetDB().Model(&dt).Save(&dt)
	return nil,nil
}

func (dt DeviceTopicModel) SelectByDevice() (dts []DeviceTopicModel) {
	database.GetDB().Model(&dt).Where("did = ?",dt.Did).Find(&dts)
	return
}

